var GraceJS = require("../../Grace.JS/grace.js");
import {
    apiServer
} from '../../common.js';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id:'',
        pid:'',
        name:'',
        detail:{},
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this
        that.setData({
            id:options.id,
            pid:options.pid,
            name:options.title,
        }, function(){
            GraceJS.setNavBar({
                title: options.title
            }); 
            that.getDetail()
        })
    },

    xia: function(e){
        console.log(e)
        var that = this;
        var id = e.currentTarget.dataset.id
        var name = e.currentTarget.dataset.name
        that.setData({
            id: id,
            name: name,
            // detail:'',
        }, function(){
            GraceJS.setNavBar({
                title: name
            }); 
            that.getDetail()
        })
    },

    getDetail: function () {
        var that = this;
        GraceJS.get(
            apiServer + 'resume.Tutorial/TutorialDetail', {
                id: that.data.id,
                pid: that.data.pid,
            }, {},
            function (res) {
                if (res.code == 0) {
                    console.log(res, 'dads')
                    that.setData({
                        detail: res.data,
                    }, function(){
                        wx.pageScrollTo({
                            scrollTop: 0
                          });
                    })
                } else {
                    GraceJS.msg(res.message)
                }
            }
        )
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: this.data.detail.name,
            path: '/pages/tutorial-detail/index?id='+this.data.detail.id,
        }
    },

    // 分享朋友圈
    onShareTimeline: function () {
        return {
            title: this.data.detail.name,
            path: '/pages/tutorial-detail/index?id='+this.data.detail.id,
        }
    }
})